package feature

import (
	"gohub/pkg/app"
	"gohub/pkg/database"
	"gohub/pkg/paginator"

	"github.com/gin-gonic/gin"
)

// Get 通过 ID 获取
func Get(idstr string) (featureModel Feature) {
	database.DB.Where("id", idstr).First(&featureModel)
	return
}

// All 获取所有数据
func All() (Features []Feature) {
	database.DB.Order("id").Find(&Features)
	return
}

// Paginate 分页
func Paginate(c *gin.Context, perPage int) (features []Feature, paging paginator.Paging) {
	paginator := paginator.New(c, database.DB.Model(&Feature{}), app.V1URL(database.TableName(&Feature{})))
	paging = paginator.Paginate(&features)
	return
}

// func Paginate(c *gin.Context, perPage int) (features []Feature, paging paginator.Paging) {
// 	paging = paginator.Paginate(
// 		c,
// 		database.DB.Model(Feature{}),
// 		&features,
// 		app.V1URL(database.TableName(&Feature{})),
// 		perPage,
// 	)
// 	return
// }
